<?php
namespace app\index\controller\traits;

trait Skill
{

/**
 * 技能表获取
 */
    function getSkillArr($xml_file_skillname, $xml_file_skillid)
    {

        $skill_name = $this->getArrFromXml($xml_file_skillname);

        $xmlNode = simplexml_load_file($xml_file_skillid);

        $temp = \app\ux\UtilXml::xmlToArray($xmlNode);
        $temp = $temp ? $temp["RECORDS"]["RECORD"] : $temp;

        if ($temp) {
            $rtn = array();
            foreach ($temp as $k => $v) {
                $arr      = explode(";", $v['skill_id']);
                $name_arr = array();
                foreach ($arr as $ko => $vo) {
                    $name_arr[$ko] = $skill_name[$vo];
                }
                $rtn[$k]['skill_name'] = $name_arr;
            }
        }
        return $rtn;
    }

/**
 * 配置表
 */
    function getArrFromXml($xml_file, $key, $value)
    {

        $xmlNode = simplexml_load_file($xml_file);
        $temp    = \app\ux\UtilXml::xmlToArray($xmlNode);
        $temp    = $temp ? $temp["RECORDS"]["RECORD"] : $temp;
        if ($temp) {
            $rtn = array();
            foreach ($temp as $k => $v) {
                $rtn[$v[$key]] = $v[$value];
            }
        }
        return $rtn;
    }
}
